package iammry.com.utils;

import android.content.Context;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by kim
 * on 2016/11/21 0021.
 */

public class GetAssertPath {

    /**
     * @param context 上下文
     * @param filename 文件名
     * @return
     */
    public String getPath(Context context, String filename) {

        InputStream abpath = context.getClass().getResourceAsStream("/assets/filename");
        try {
            return inputStreamToString(abpath);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }


    }

    /**
     *
     * @param is
     * @return
     * @throws IOException
     */
    public String inputStreamToString(InputStream is) throws IOException {

        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        int ch;
        while ((ch = is.read()) != -1) {
            bytestream.write(ch);
        }
        byte imgdata[] = bytestream.toByteArray();
        bytestream.close();

        return new String(imgdata);
    }


}
